import { getUserInfo }  from '@/API/yjl-Api'
export default {
  namespaced: true,
  state: {
    userInfo :JSON.parse(localStorage.getItem('edb-userinfo')) || {
         permissions: null,
         user: null,
         roles: null
    }
  },
  mutations: {
    changeUserInfo(state, payload) {
       state.userInfo = payload
       // 将用户信息存储到本地
       localStorage.setItem('edb-userinfo', JSON.stringify(state.userInfo))
    }
  },
  actions: {
     async asyncGetUserInfo({commit}) {
        let getUserInfoRes = await getUserInfo()
        console.log(getUserInfoRes);
        if(!getUserInfoRes) return
        commit('changeUserInfo', {
          permissions: getUserInfoRes.permissions,
          user: getUserInfoRes.user,
          roles: getUserInfoRes.roles
        })
     }
  }
}